#!/bin/sh
# STDIO mode startup script for C++ Function Call Tree Analysis MCP Server
set -e

# Change to script directory
cd "$(dirname "$0")"

# Create independent virtual environment (if it doesn't exist)
if [ ! -d ".venv" ]; then
    echo "Creating virtual environment..." >&2
    uv venv
    echo "Installing dependencies..." >&2
    echo "Note: Dependency installation may take several minutes. Please wait..." >&2
    uv sync
fi

# Check for optional Clang installation
if ! python -c "import clang.cindex" 2>/dev/null; then
    echo "Warning: Clang Python bindings not found. Advanced Clang-based analysis will be disabled." >&2
    echo "To enable Clang analysis, install: pip install libclang" >&2
fi

# Start STDIO mode MCP server
echo "Starting C++ Function Call Tree Analysis MCP Server..." >&2
uv run python server.py
